import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:photo_frame/mixin/auto_hide_loading.dart';
import 'package:photo_frame/net/http_manager.dart';
import 'package:photo_frame/router/router_context.dart';
import 'package:photo_frame/router/router_mapping.dart';
import 'package:photo_frame/user/user_manager.dart';
import 'package:photo_frame/utils/localization_util.dart';
import 'package:provider/provider.dart';

bool splash = true;

class SplashPage extends StatelessWidget {
  const SplashPage();

  @override
  Widget build(BuildContext context) {
    Future.delayed(Duration(milliseconds: 150)).whenComplete(() {
      _checkLogin();
    });
    return ColoredBox(
      color: Colors.white,
      child: Center(
        child: Image.asset(
          "images/icon_splash.png",
          width: 413,
          height: 72,
        ),
      ),
    );
  }

  _checkLogin() {
    if (!splash) return;
    splash = false;
    if (UserManager.instance.isLoggedIn()) {
      ARouter.instance.pagePushReplacement("/main");
    } else {
      ARouter.instance.pagePushReplacement("/login");
    }
  }
}
